/*    */ package com.wgcloud.util;
/*    */ 
/*    */ import cn.hutool.core.lang.Snowflake;
/*    */ import cn.hutool.core.util.IdUtil;
/*    */ import com.wgcloud.config.CommonConfig;
/*    */ import javax.annotation.PostConstruct;
/*    */ import org.slf4j.Logger;
/*    */ import org.slf4j.LoggerFactory;
/*    */ import org.springframework.beans.factory.annotation.Autowired;
/*    */ import org.springframework.stereotype.Component;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ @Component
/*    */ public class IdGeneratorSnowflake
/*    */ {
/* 38 */   private static final Logger logger = LoggerFactory.getLogger(com.wgcloud.util.IdGeneratorSnowflake.class);
/*    */ 
/*    */   
/*    */   @Autowired
/*    */   CommonConfig commonConfig;
/*    */ 
/*    */   
/* 45 */   private long workerId = 0L;
/*    */ 
/*    */ 
/*    */ 
/*    */   
/* 50 */   private long datacenterId = 1L;
/* 51 */   private Snowflake snowflake = null;
/*    */ 
/*    */   
/*    */   @PostConstruct
/*    */   public void init() {
/*    */     try {
/* 57 */       if (!"master".equals(this.commonConfig.getNodeType())) {
/* 58 */         String slaveId = this.commonConfig.getNodeType().replace("slave", "");
/* 59 */         this.workerId = Long.valueOf(slaveId).longValue();
/*    */       } 
/* 61 */       this.snowflake = IdUtil.createSnowflake(this.workerId, this.datacenterId);
/* 62 */       logger.info("当前机器的workerId: {}", Long.valueOf(this.workerId));
/* 63 */     } catch (Exception e) {
/* 64 */       this.snowflake = IdUtil.createSnowflake(this.workerId, this.datacenterId);
/* 65 */       logger.error("当前机器的workerId获取失败", e);
/*    */     } 
/*    */   }
/*    */ 
/*    */   
/*    */   public synchronized long snowflakeId() {
/* 71 */     return this.snowflake.nextId();
/*    */   }
/*    */ }


/* Location:              /Users/zhangyongxin/soft-install/wgcloud/wgcloud-v3.3.5/server/bank/wgcloud-server-release.jar!/BOOT-INF/classes/com/wgcloud/util/IdGeneratorSnowflake.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */